import { createRouter, createWebHistory } from 'vue-router'
import home from '@/views/Home/home.vue'
import { Toast } from "vant";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      name: 'home',
      component: home
    },
    {
      path: "/category",
      name: "category",
      component: () => import("@/views/category.vue")
    },
    {
      path: "/cart",
      name: "cart",
      component: () => import("@/views/Cart/cart.vue")
    },
    {
      path: "/my",
      name: "my",
      component: () => import("@/views/my.vue")
    },
    {
      path: "/goodsDetail",
      name: "goodsDetail",
      component: () => import("@/views/detail.vue")
    },
    {
      path: "/regsiter",
      component: () => import("@/views/Login/register.vue")
    },
    {
      path: "/leadingEnterprise",
      component: () => import("@/views/LeadingEnterprise/index.vue")
    }, {
      path: "/categoryPro",
      component:()=>import('@/views/categoryPro.vue')
    },
    
    {
      path: "/personFix",
      component:()=>import('@/views/personFix.vue')
    },
  ]
})
// 做路由拦截
router.beforeEach((to, from, next) => {
  if (to.fullPath == '/my' || to.fullPath == '/cart') {
    if (sessionStorage.getItem("token")) {
      next()
    }
    else {
      Toast("亲，您还未登录哦")
      next("/regsiter")
    }
  } else {
    next()
  }
})
export default router
